﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using UCL.Powersource;

namespace PowersourceUIToolkit
{
    public class ViewCacheItem : IDisposable
    {
        public IViewModel ViewModel { get; private set; }
        public FrameworkElement View { get; private set; }
        public object Context { get; private set; }



        public ViewCacheItem(IViewModel vm1, FrameworkElement view1, object context1 = null)
        {
            if (vm1 == null || view1 == null) throw new ArgumentNullException("ViewCache item cannot be created with ViewModel and/or View equals to null");
            this.ViewModel = vm1;
            this.View = view1;
            this.Context = context1;
            //this.isDefault = isDefault || (context1==null);
        }


        public void Dispose()
        {
            string viewName = "#NULL#";
            if (View != null) viewName = View.Name;
            Trace.WriteLine(string.Format("Disposing ViewCacheItem for {0}", viewName));
            View = null;
            ViewModel = null;
            Context = null;
        }


    }

}
